package com.example.app.entity

data class Country(val name: String, val continient: String, val population: Int)

class CountryTest {
    fun isBigEuropeanCountry(country: Country): Boolean {
        return country.continient == "EU" && country.population > 10000
    }
}

class CountryApp {
    fun filterCountry(countries: List<Country>, test: (country: Country) ->
    Boolean): List<Country> {
        val res = mutableListOf<Country>()
        for (c in countries) {
            if (test(c)) {
                res.add(c)
            }
        }
        return res
    }
}


fun main(args: Array<String>) {

    val country1 = Country("英国", "EU", 12000)
    val country2 = Country("中国", "AS", 120000)
    val country3 = Country("刚果", "AF", 8000)

    val countries: List<Country> = listOf(country1, country2, country3)

    val countryTest = CountryTest()
    val countryApp = CountryApp()
//    val res = countryApp.filterCountry(countries, countryTest::isBigEuropeanCountry)

    val res = countryApp.filterCountry(countries, { country ->
        country.continient == "EU" && country
                .population > 10000
    })

    for (country in res) {
        println(country.name + "在欧洲")
    }

    //sum是一个类型为 (Int, Int) -> Int 的函数，Lambda表达式 { x: Int, y: Int -> x + y } 是sum的值
    val sum: (Int, Int) -> Int = { x: Int, y: Int -> x + y }

    //类型推倒为：
    val sum1 = { x: Int, y: Int -> x + y }

    //或者类型推倒为：
    val sum2: (Int, Int) -> Int = { x, y -> x + y }
}



